package com.cainiao.stock.handler;


import com.cainiao.stock.enums.CodeEnum;
import com.cainiao.stock.exception.StockException;
import com.cainiao.stock.response.ResponseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(value = StockException.class)
    public ResponseResult<?> handleException(StockException e){
        return ResponseResult.error(e.getCode());
    }

    @ExceptionHandler
    public ResponseResult<?> handleUnKnowException(Exception e){
        log.error(e.getMessage(),e);
        return  ResponseResult.error(CodeEnum.SYSTEM_ERROR);
    }
}

